use bytes::{BytesMut};
use num_enum::{IntoPrimitive, TryFromPrimitive};

/// 云平台协议pkt最小长度
pub const CLOUD_PKT_MIN_LEN: u8 = 0x08;

///
/// 协议格式化
///
pub trait PayloadFormat: Send + Sync {
    fn serialize(&mut self) -> BytesMut {
        BytesMut::zeroed(0)
    }
    fn get_len(&mut self) -> usize {
        0
    }
}

///
/// 服务器交互命令码
/// See B.3.3.1
///
#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum CloudCmdType {
    VehicleLogin = 0x01,
    RealTimeInfoUpload = 0x02,
    HistoryInfoUpload = 0x03,
    VehicleLogout = 0x04,
    PlatformLogin = 0x05,
    PlatformLogout = 0x06,
    VehicleHeartbeat = 0x07,
    VehicleTimeCal = 0x08,
    /// 0x09 - 0x7F 为上行数据,自定义
    UserCustomA = 0x09,
    ServerQuery = 0x80,
    ServerSetup = 0x81,
    ServerCtrl = 0x82,
}

///
/// 加密类型
/// See B.3.2
///
#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum EncryptionType {
    None = 0x01,
    RSA = 0x02,
    AES128 = 0x03,
    Exception = 0xFE,
    Invalid = 0xFF,
}

///
/// 应答类型标志
/// See 6.3.2 Table-4
///
#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
#[repr(u8)]
pub enum ResponseType {
    OK = 0x01,
    Error = 0x02,
    VINRepeat = 0x03,
    Command = 0xFE,
}